package com.android.tea;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.tea.util.Utils;
import com.android.tea.widght.ContactPopupWindow;

public class TeaFriendDetailActivity extends Activity implements OnClickListener{
	private TextView text_area;
	private TextView text_cellphone;
	private TextView text_phone;
	private TextView text_signal;
	private Button btn_send;
	private TextView text_accout;
	private ImageView image_signal;
	private ContactPopupWindow contactPopup;
	private Button btn_more;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState); 
		setContentView(R.layout.contact_detail);
		
		initComponents();
	}

	private void initComponents() {
		btn_more = (Button)findViewById(R.id.btn_more);
		text_accout = (TextView)findViewById(R.id.text_accout);
		image_signal = (ImageView)findViewById(R.id.signal_image);
		text_area = (TextView)findViewById(R.id.text_area);
		text_cellphone = (TextView)findViewById(R.id.text_cellphone);
		text_phone = (TextView)findViewById(R.id.text_phone);
		text_signal = (TextView)findViewById(R.id.text_signal);
		btn_send = (Button)findViewById(R.id.btn_send);
		btn_more.setOnClickListener(this);
		
	}
	
	private void showContactPopup() {
		if (contactPopup == null) {
			contactPopup = new ContactPopupWindow(this, R.drawable.bg_share_popup_1);
		}
		int[] btnShareLoc = new int[2];
		btn_more.getLocationInWindow(btnShareLoc);
//		int offY = Utils.getScreenHeight(this) - btnShareLoc[1] + Utils.dipToPixels(this, 5);
		int offY = btnShareLoc[1] + Utils.dipToPixels(this, 5);
		int orientation = getResources().getConfiguration().orientation;
		contactPopup.show(btn_more, orientation, 0, offY);
		registerContactButton();
	}

	private void registerContactButton() {
		if (contactPopup!=null&&contactPopup.getStarFriendButton() != null) {
			contactPopup.getStarFriendButton().setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					//TODO 注册点击事件
				}
			});
		}

		if (contactPopup!=null&&contactPopup.getNoteButton() != null) {
			contactPopup.getNoteButton().setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					//TODO 注册点击事件
				}
			});
		}
		
		if (contactPopup!=null&&contactPopup.getDeleteFriendButton() != null) {
			contactPopup.getDeleteFriendButton().setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					//TODO 注册点击事件
				}
			});
		}
		
		if (contactPopup!=null&&contactPopup.getDeleteButton() != null) {
			contactPopup.getDeleteButton().setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					//TODO 注册点击事件
				}
			});
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_send:
			//send message
			break;
			
		case R.id.btn_more:
			showContactPopup();

		default:
			break;
		}
	}
}
